<?php

namespace app\controller\admin\system\recruit;

use app\common\repositories\system\recruit\RecruitRepository;
use crmeb\basic\BaseController;
use think\App;

class Recruit extends BaseController
{

    protected $repository;

    public function __construct(App $app, RecruitRepository $repository)
    {
        parent::__construct($app);
        $this->repository = $repository;
    }

    /**
     * @return mixed
     * @author: fupeng
     * @day: 2024/5/7
     * 列表
     */
    public function lst()
    {
        $where = $this->request->params(['job','status']);
        [$page, $limit] = $this->getPage();
        $data = $this->repository->getList($where,$page, $limit);
        return app('json')->success($data);
    }

    public function create()
    {
        $data = $this->request->params([
            'job',
            'price',
            'label',
            'info',
            'content',
            'phone',
            ['status', 0],
            ['sort', 0]
        ]);
        $this->repository->create($data);
        return app('json')->success('添加成功');
    }

    public function update($id)
    {
        $data = $this->request->params([
            'job',
            'price',
            'label',
            'info',
            'content',
            'phone',
            ['status', 0],
            ['sort', 0]
        ]);
        $this->repository->update($id, $data);
        return app('json')->success('编辑成功');
    }

    public function switchStatus($id)
    {
        $status = $this->request->param('status', 0) == 1 ? 1 : 0;
        if(!$this->repository->get($id)) return app('json')->fail('数据不存在');
        $this->repository->switchStatus($id, ['status' => $status]);
        return app('json')->success('修改成功');
    }


    public function detail($id)
    {
        if (!$this->repository->merExists($id))
            return app('json')->fail('数据不存在');
        return app('json')->success($this->repository->get($id));
    }

    public function delete($id)
    {
        $this->repository->delete($id);
        return app('json')->success('删除成功');
    }
}
